﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ReallyReallyReallySimpleRogueLike;
using System.Drawing;
using ReallyReallyReallySimpleRoguelikeData;

namespace ReallyReallyReallySimpleRoguelike.Entities
{
    public class Tile
    {
        protected TileData TileData = new TileData();
        public bool HasChanged;

        public Point Position 
        {
            get { return new Point(TileData.X, TileData.Y); }
        }

        public int X 
        {
            get {return (TileData.X);}
            set { TileData.X = value; }
        }

        public int Y
        {
            get { return (TileData.Y); }
            set { TileData.Y = value; }
        }

        public ConsoleColor Color
        {
            get { return (TileData.Color); }
            set { TileData.Color = value; HasChanged = true; }
        }

        public string ImageCharacter
        {
            get { return (TileData.ImageCharacter); }
            set { TileData.ImageCharacter = value; HasChanged = true; }
        }

        public Tile() { }

        public Tile(int x, int y)
            : base()
        {
            Initialize(x, y);
        }

        public Tile(Point point)
            : base()
        {
            Initialize(point.X, point.Y);
        }

        public void Initialize(int x, int y) 
        {
            this.X = x;
            this.Y = y;
            ImageCharacter = Constants.TileImage;
            Color = Constants.TileColor;
            HasChanged = false;
        }
        public void Move( Point point, Constants.Direction direction,int distance)
        {
                       
            switch (direction)
            {
                case Constants.Direction.N:
                    TileData.Y -= distance;
                    break;
                case Constants.Direction.S:
                    TileData.Y += distance;
                    break;
                case Constants.Direction.E:
                    TileData.X += distance;
                    break;
                case Constants.Direction.W:
                    TileData.X -= distance;
                    break;      
            }
        }

        public void Kill(Creature creature)
        {
            creature.Hits = 0;
        }

        public bool IsVisuallySimilar(Tile tile) 
        {
            if (tile != null)
            {
                if (this.Color == tile.Color && this.ImageCharacter == tile.ImageCharacter)
                    return true;
            }
            else 
            {
                return true;
            }
            return false;
        
        }
    }
}
